package com.xialing.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xialing.manager.LinkGroupManager;
import com.xialing.mapper.LinkGroupMapper;
import com.xialing.model.LinkGroupDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * @Author: xialing
 * @Description
 */
@Component
public class LinkGroupManagerImpl implements LinkGroupManager {

    @Autowired
    private LinkGroupMapper linkGroupMapper;

    /**
     * 添加分组
     * @param linkGroupDO
     * @return
     */
    @Override
    public int add(LinkGroupDO linkGroupDO) {

        return linkGroupMapper.insert(linkGroupDO);
    }

    /**
     * 删除分组
     * @param accountNo
     * @param groupId
     * @return
     */
    @Override
    public int delete(long accountNo, Long groupId) {
        LambdaQueryWrapper<LinkGroupDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(LinkGroupDO::getId,groupId).eq(LinkGroupDO::getAccountNo,accountNo);
        return linkGroupMapper.delete(queryWrapper);
    }

    @Override
    public LinkGroupDO detail(long accountNo, Long groupId) {
        return linkGroupMapper.selectOne(new LambdaQueryWrapper<LinkGroupDO>().eq(LinkGroupDO::getId,groupId).eq(LinkGroupDO::getAccountNo,accountNo));

    }

    @Override
    public List<LinkGroupDO> listAllGroup(long accountNo) {
        return linkGroupMapper.selectList(new LambdaQueryWrapper<LinkGroupDO>().eq(LinkGroupDO::getAccountNo,accountNo));
    }

    @Override
    public int updateById(LinkGroupDO linkGroupDO) {
        return linkGroupMapper.update(linkGroupDO,new LambdaQueryWrapper<LinkGroupDO>().eq(LinkGroupDO::getId,linkGroupDO.getId()).eq(LinkGroupDO::getAccountNo,linkGroupDO.getAccountNo()));
    }
}
